function instanceosf(left, right) {
  // const arr = [null, undefined, Number, String, BigInt, 'function']
  // if (!arr.includes(typeof left)) { }

  // 相当上面两行方法，但是下面的更容易理解
  if (left === null || typeof left !== "object") {
    return false;
  }

  while (true) {
    if (left === null) {
      return;
    }

    // 左侧的隐式原型 === 右侧的显式原型
    if (left.__proto__ === right.prototype) {
      return true;
    }
    left = left.__proto__;
  }
}

function instanceosfV3(left, right) {
  if (typeof left === null || typeof left !== "object") {
    return false;
  }

  while (true) {
    if (left === null) {
      return false;
    }

    if (left.__proto__ === right.prototype) {
      return true;
    }
    left = left.__proto__;
  }
}

console.log(instanceosfV3({}, Object));
console.log(instanceosfV3(new Date(), Date));
console.log(instanceosfV3(111, Date));
console.log(instanceosfV3({}, Date));


function instanceOf(left, right) {
  if (left === null || typeof left !== "object") {
    return false;
  }

  while (true) {
    if (left === null) {
      return false;
    }
    if (left.__proto__ === right.prototype) {
      return true;
    }
    left = left.__proto__;
  }
}


function instanceOfV3(left, right) {
  if (typeof left !== "object" || left === null) {
    return false;
  }

  while (true) {
    if (left === null) {
      return false;
    }
    if (left.__proto__ === right.prototype) {
      return true;
    }

    left = left.__proto__;
  }
}

function instanceOfV4(left, right) {
  if (typeof left !== "object" || left === null) {
    return false;
  }

  while (true) {
    if (left === null) {
      return false;
    }
    if (left === right.prototype) {
      return true;
    }
    left = left.__proto__;
  }
}


/**
 *原理：左侧的隐式原型，是否在右侧的property上
 * 左侧在其原型链上寻找，是否等于右侧的property
 */